package com.xt.shop.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import com.xt.shop.Model.DiscountInfo;
import com.xt.shop.service.DiscountInfoService;
import com.xt.shop.mapper.DiscountInfoMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 24862
* @description 针对表【discount_info】的数据库操作Service实现
* @createDate 2024-01-08 16:00:06
*/
@Service
public class DiscountInfoServiceImpl extends ServiceImpl<DiscountInfoMapper, DiscountInfo>
    implements DiscountInfoService{
    @Resource
    DiscountInfoMapper discountInfoMapper;

    @Resource
    ShopInfoServiceImpl shopInfoService;

    @Resource
    UserInfoServiceImpl userInfoService;

    @Override
    public PageInfo<DiscountInfo> queryList(int page, int item) {
        PageMethod.startPage(page,item);
        List<DiscountInfo> discountInfos = discountInfoMapper.selectList(new QueryWrapper<DiscountInfo>()
                .eq("state",1)
        );
        for (DiscountInfo d :
                discountInfos) {
            d.setShopId(shopInfoService.getById(d.getShopId()).getName());
            d.setUserId(userInfoService.getById(d.getUserId()).getUsername());
        }
        PageInfo<DiscountInfo> pageInfo=new PageInfo<>(discountInfos);
        return pageInfo;
    }
}




